﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using AdmBase;
using Guedes_Library;

public partial class admin_pages_noticias : TelaBase
{
    protected void Page_Load(object sender, EventArgs e)
    {
        IsLogado();
        string id = Request.QueryString["id"];
        if (id != null && !IsPostBack)
        {
            news n = NBusiness.GetById(int.Parse(id));
            if (n == null)
                Response.Redirect("~/admin/pages/noticia/Default.aspx");
            txtDica.Text = n.Dica;
            txtTitulo.Text = n.Titulo;
            hdId.Value = n.ID.ToString();
        }
    }

    private NoticiaBusiness nBusiness;

    public NoticiaBusiness NBusiness
    {
        get
        {
            if (nBusiness == null)
                nBusiness = new NoticiaBusiness();
            return nBusiness;
        }
        set { nBusiness = value; }
    }

    protected void Save(object sender, EventArgs e)
    {
        Retorno retorno;
        news n = new news();
        if (hdId.Value != "")
            n.ID = int.Parse(hdId.Value);
        n.Dica = txtDica.Text;
        n.Titulo = txtTitulo.Text;
        retorno = NBusiness.Salvar(n);
        ShowMensagem("Atenção", retorno.Mensagem);
        if (!retorno.Error)
            LimpaCampo();
    }

    public void LimpaCampo()
    {
        txtDica.Text = String.Empty;
        txtTitulo.Text = String.Empty;
        hdId.Value = String.Empty;
    }
}